package ewms.vo.transfer_warehouse;

import com.fasterxml.jackson.annotation.JsonFormat;
import ewms.common.annotation.Excel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import lombok.experimental.Accessors;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Accessors(chain = true)
@ToString
public class EwmsTransferWarehouseWrapperVo implements Comparable<EwmsTransferWarehouseWrapperVo> {

	/**
	 * 危废分类ID
	 */
	@ApiModelProperty("危废分类ID")
	private Long wasteTypeId;

	/**
	 * 危废编码
	 */
	@ApiModelProperty("危废编码")
	private String wasteCode;

	/**
	 * 包装类别
	 */
	@ApiModelProperty("包装类别")
	private String packageType;

	/**
	 * 处置方式
	 */
	@ApiModelProperty("处置方式")
	private String handlerMethod;

	/**
	 * 危废形态
	 */
	@ApiModelProperty("危废形态")
	private String wasteShape;

	/**
	 * 安全措施
	 */
	@ApiModelProperty("安全措施")
	private String securityMeasure;

	/**
	 * 危险特性
	 */
	@ApiModelProperty("危险特性")
	private String hazardousCharacteristics;

	/**
	 * 危废ID
	 */
	@ApiModelProperty("危废ID")
	private Long wasteId;

	/**
	 * 批次号码
	 */
	@Excel(name = "批次号码", width = 30)
	@ApiModelProperty("批次号码")
	private String batchNumber;

	/**
	 * 危废名称
	 */
	@Excel(name = "危废名称", width = 45)
	@ApiModelProperty("危废名称")
	private String wasteName;

	@Excel(name = "转库记录", width = 45)
	private String transferRecord;

	/**
	 * 现存仓库名称
	 */
//	@Excel(name = "仓库名称")
	@ApiModelProperty("现存仓库名称")
	private String warehouseName;

	/**
	 * 危废重量
	 */
	@Excel(name = "仓库名称", scale = 2)
	@ApiModelProperty("危废重量")
	private BigDecimal wasteWeight;

	/**
	 * 预估重量
	 */
	@ApiModelProperty("预估重量")
	private BigDecimal wasteDiscreetWeight;

	/**
	 * 所属行业
	 */
	@ApiModelProperty("所属行业")
	private String industryName;

	/**
	 * 危废分类
	 */
	@ApiModelProperty("危废分类")
	private String wasteTypeName;

	/**
	 * 入库日期
	 */
	@Excel(name = "入库日期", width = 30, dateFormat = "yyyy-MM-dd")
	@JsonFormat(pattern = "yyyy-MM-dd")
	@ApiModelProperty("入库时间")
	private Date entryDate;

	/**
	 * 入库操作者
	 */
	@Excel(name = "入库操作者")
	@ApiModelProperty("入库操作者")
	private String entryOperator;

	/**
	 * 库存ID
	 */
	@ApiModelProperty("库存ID")
	private Long wasteInventoryId;

	/**
	 * 现存仓库id
	 */
	@ApiModelProperty("现存仓库id")
	private Long warehouseId;

	/**
	 * 备注
	 */
	@ApiModelProperty("备注")
	private String remark;

	/**
	 * 转库明细记录
	 */
	@ApiModelProperty("备注")
	private List<EwmsTransferWarehouseDetailWrapperVo> transferWarehouseDetailList;

	/**
	 * 转换转库记录数据
	 *
	 * @return
	 */
	public void convertTransferRecord() {
		this.transferRecord = this.transferWarehouseDetailList.stream()
			.map(item -> item.getTransferItem())
			.collect(Collectors.joining("   "+ System.lineSeparator()));
	}

	@Override
	public int hashCode() {
		return this.wasteInventoryId.hashCode();
	}

	@Override
	public boolean equals(Object obj) {
		boolean isEquals = false;
		if (this == obj) {
			isEquals = true;
		} else if (obj instanceof EwmsTransferWarehouseWrapperVo) {
			isEquals = this.wasteInventoryId.equals(((EwmsTransferWarehouseWrapperVo) obj).wasteInventoryId);
		}
		return isEquals;
	}

	@Override
	public int compareTo(EwmsTransferWarehouseWrapperVo transferWarehouseWrapperVo) {
		return this.wasteInventoryId.compareTo(transferWarehouseWrapperVo.wasteInventoryId);
	}

	@Data
	@Accessors(chain = true)
	public static class EwmsTransferWarehouseDetailWrapperVo {
		/**
		 * 转库ID
		 */
		@ApiModelProperty("转库ID")
		private Long transferWarehouseId;

		/**
		 * 转库明细ID
		 */
		@ApiModelProperty("转库ID")
		private Long transferWarehouseDetailId;

		/**
		 * 转至仓库id
		 */
		@Excel(name = "转至仓库id")
		@ApiModelProperty("转至仓库id")
		private Long toWarehouseId;

		/**
		 * 转至仓库名称
		 */
		@Excel(name = "转至仓库名称")
		@ApiModelProperty("转至仓库名称")
		private String toWarehouseName;

		/**
		 * 原仓库id
		 */
		@Excel(name = "原仓库id")
		@ApiModelProperty("原仓库id")
		private Long fromWarehouseId;

		/**
		 * 原仓库名称
		 */
		@Excel(name = "原仓库名称")
		@ApiModelProperty("原仓库名称")
		private String fromWarehouseName;

		/**
		 * 转库时间
		 */
		@Excel(name = "转库时间", width = 30, dateFormat = "yyyy-MM-dd")
		@JsonFormat(pattern = "yyyy-MM-dd")
		@ApiModelProperty("转库时间")
		private Date transferDate;

		/**
		 * 转库操作者
		 */
		@Excel(name = "转库操作者")
		@ApiModelProperty("转库操作者")
		private String transferOperator;

		/**
		 * 最大转库时间
		 */
		@JsonFormat(pattern = "yyyy-MM-dd")
		private Date maxTransferDate;

		public String getTransferItem() {
			return this.fromWarehouseName + " > " + this.toWarehouseName;
		}

	}
}
